// locutor
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id: DG.scala 231 2009-09-16 09:09:29Z nmueller $
package info.kwarc.locutor.dg

//import java.net._
//import java.text.MessageFormat.{format}
//
//import scaup.Views._
//import scaup.data._
//import scaup.xml.xpath.{Expr => XPath}
//
//case class DGWarning(message: String) extends Throwable(message)
//case class DGError(message: String) extends Throwable(message)
//
///**
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//trait Rooted {
//  val root: Option[Node]
//}
//
///**
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//object DG {
//  /** The empty dependency graph
//   */
//  val empty = new DG(Graph("DG")) with Rooted { val root = None }
//  /** Create read only dependency graph model
//   */
//  def apply(g: Graph) = new DG(g)
//}
//
///** Dependency Graph Model
// * 
// * @param store Internal dependency graph representation
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//class DG(val store: Graph) {
//  import DG._
//
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  //
//  // DG modifications
//  //
//  // Note: There will be none methods for identification and analysis of dependencies (recall, maintenance of DGs is
//  //       defined to be identification, maintenance, and analysis). These are outsourced to 3rd party tools.
//  //  
//  // @todo Does this also hold for analysis of dependencies???  
//  //
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  
//  /** Disjoin statements of g and into the current dependency graph model
//   * 
//   * @param g dependency graph
//   * @return A dependency graph model dijoint extended by g */
////  def +(g: Graph): DG = g match {
////    case Graph(false,true,Some(id),_@_*) if strict(E(g)) =>
////      DG(store + Ƭᵡ(g))
////    case _                                               => 
////      throw DGError("\'" + g + "\' is not a valid dependency graph.")
////  } 
//  
//  // @todo: reassess after GraphSpec; Property strictness, i.e. no self-arcs
////  private def strict(cs: List[EdgeComponent]): Boolean = cs match {
////    case Nil                                        => true
////    case Node(fi,_)::Node(si,_)::tl if fi == si     => false
////    case (x@Subgraph(_,_*))::(y@Subgraph(_,_*))::tl =>
////      !(V(x) exists (n => (V(y) contains n))) &&
////      strict(E(x)) &&
////      strict(E(y)) &&
////      strict(tl)
////    case z@_                                        => strict(z.drop(1))
////  } 
////  private def strict(es: Set[Edge]): Boolean = true //@fixme (true /: (for(Edge(_,stmts@_*) <- es) yield strict(stmts.toList)))(_ && _)
//  
//  // @todo Implement after GraphSpec; Transform and extract
////  private def Ƭᵡ(g: Graph): List[Statement] = {
////    val nodes = V(g) //map (mkInfom(g.id.get.toURI,_))
////    val edges = E(g)
////    Nil
////  }
//  // @todo reassess after GraphSpec
////  private def mkInfom(u: URI, v: Node): Infom = 
////    (v \@ "path") match {
////      case Some(x) => 
////        Infom(Path(u,x.toXPath), v.attributes filter {case Attr("xpath",_) => false})
////      case None =>
////        throw DGError(format("''{0}'' is not a valid INFOM.",v))
////    }  
////  private def prefixed(prefix: String, statements: Statement*): Seq[Statement] = statements map {
////    case Subgraph(id, statements@_*) => Subgraph(id, prefixed(prefix, statements:_*):_*)
////    case n@Node(id,as@_*) => Infom("path")
////      //val quoted = ((s: String) => "\"(.*)\"".r findFirstIn s)
////      //val labeled = ((s: Iterable[Attr]) => s find {case Attr("label",_) => true})
////      //val l = labeled(as)
////      //val q = quoted(id)
////      //println()      
////      Node(prefix+"#"+id,as:_*)
////    case Edge(as,ns@_*) => Edge(as,(ns map {
////      case Subgraph(id, statements@_*) => Subgraph(id, prefixed(prefix, statements:_*):_*)
////      case Node(id,as@_*) => Node(prefix+"#"+id,as:_*)
////    }):_*)
////    case Attr(n,v) => Attr(n,v)
////    case Attrs(k,as@_*) => Attrs(k,as:_*)
////  }
//  
//  //@todo implement + for nodes and edges
//  //@todo implement - for graphs, nodes and edges
//  
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  //
//  // Node queries
//  //
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  
//  /** Get the set of all nodes that are identified via XPath expression p
//   */
//  def \(p: XPath): Set[Infom] = error("not yet implemented")
//  /** Get the set of all nodes that are identified via XPath expression p or an subexpression of p
//   */
//  def \<(p: XPath): Set[Infom] = error("not yet implemented")
//  /** Get the set of all nodes that are identified via XPath expression p of n
//   */
//  def \(n: Node): Set[Infom] = error("not yet implemented")
//  /** Get the set of all nodes that are identified via XPath expression p of n or an subexpression of p of n
//   */
//  def \<(n: Node): Set[Infom] = error("not yet implemented")
//  /** Get the set of all nodes that are labled with the same attributes as f := Node(_, as)
//   */
//  def \(f: String => Node): Set[Infom] = error("not yet implemented")
//  /** Get the set of all nodes that are labled with the attribute a
//   */
//  def \(a: Attr): Set[Infom] = error("not yet implemented")
//  //@todo What is \< on attributes?
//  /** Get the set of all incoming nodes of n
//   */
//  def ↖(n: Node) : Set[Infom] = error("not yet implemented")
//  /** Get the set of all outgoing nodes of n
//   */
//  def ↘(n: Node) : Set[Infom] = error("not yet implemented")
//  
//  /** Get the subgraph at the node identified by the XPath expression p
//   */
//  def |(p: XPath): DG with Rooted = error("not yet implemented")
//  /** Get the subgraph at node n
//   */
//  def |(n: Node): DG with Rooted = error("not yet implemented")
//  
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  //
//  // Edge queries
//  //
//  ///////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////  
//  
//  /** Get the set of all edges that are identified via XPath expression p
//   */
//  def %(p: XPath): Set[Edge] = error("not yet implemented")
//    
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  //
//  // Subgraph queries
//  //
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
//  
//  /** Get the set of subgraphs matching g
//   */
//  def ⊑(g: Graph): Set[DG] = error("not yet implemented")
//  /** Get the set of subgraphs constitued of the set of nodes ns
//   */
//  def ⊢(ns: Set[Node]): Set[DG] = error("not yet implemented")
//  /** Get the set of subgraphs constituted of the set of edges es
//   *  Note: (g|n) ρ (es) is defined as the graph G'=(V',E') with V' ⊆ V, E' ⊆ E such that for all nodes
//   *        v ∈ V' there is a path p ⊑ es from n to v in G. */
//  def ρ(es: List[Edge]): Set[DG] = error("not yet implemented")
//  
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  //
//  // Utilities
//  //
//  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  
////  private def V(g: AbstractGraph): Set[Node] = g.nodes
////  private def E(g: AbstractGraph): Set[Edge] = g.edges
//}
